package utils

import (
	"log"
	"os"
	"io/ioutil"
	"io"
	"time"
)

var (
	Trace *log.Logger
	Info  *log.Logger
	Warn  *log.Logger
	Error *log.Logger
)

func init() {
	filePath := GetFilePath("logfile")
	file, err := os.OpenFile(filePath+time.Now().Format("2006-01-02")+".txt",
		os.O_CREATE|
			os.O_WRONLY|
			os.O_APPEND, 0666)

	if err != nil {
		Error.Println("Failed to open error log file")
	}

	Trace = log.New(ioutil.Discard, "Trace: ", log.LstdFlags|log.Lshortfile)
	Info = log.New(os.Stdout, "Info: ", log.LstdFlags|log.Lshortfile)
	Warn = log.New(os.Stdout, "Warning: ", log.LstdFlags|log.Lshortfile)
	Error = log.New(io.MultiWriter(file, os.Stderr), "Error: ", log.LstdFlags|log.Lshortfile)

}
